package com.ms.service.module.fish;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.Maps;
import com.ms.service.module.fish.game.GameUser;
import com.ms.service.module.fish.message.FishManualCodec;
import com.ms.service.module.fish.message.IWrite;
import com.ms.service.module.fish.utils.GoConstant;
import com.xpec.c4.game.utility.GUID;
import com.xpec.c4.message.MessageTypes;
import com.xpec.c4.service.message.MessageAction;

public class C4Session implements MySession{

	@SuppressWarnings("unused")
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	private Map<String,Object> attrs = Maps.newConcurrentMap();
	
	private GUID sessionId;
	
	public C4Session(GUID sessionId) {
		this.sessionId = sessionId;
	}

	@Override
	public void setAttr(String name, Object value) {
		attrs.put(name, value);
	}

	@Override
	public Object getAttr(String name) {
		return attrs.get(name);
	}

	@Override
	public Object removeAttr(String name) {
		return attrs.remove(name);
	}

	@Override
	public GameUser getUser() {
		return (GameUser) getAttr(GoConstant.USER_SESSION_KEY);
	}
	
	@Override
	public void setUser(GameUser user) {
		setAttr(GoConstant.USER_SESSION_KEY, user);
	}

	@Override
	public void sendMessage(IWrite message) {
		
		FishManualCodec data = new FishManualCodec(message);
		
		MessageAction.sendMessage(sessionId, MessageTypes.S_FISH_ACTION_DISPATCH, data);
	}

	@Override
	public void invalidate() {
	}

	@Override
	public GUID getSessionId() {
		return sessionId;
	}

}
